;_____________________________________________________________________
;---------------------------------------------------------------------
;	Title: PM App Launcher Hotkeys
;---------------------------------------------------------------------
;	Group: Overview
;
;		This file covers the main hotkeys and hotstrings of the PM 
;		App Launcher
;_____________________________________________________________________
;---------------------------------------------------------------------






;_________________________________ M A I N   H O T K E Y  <F9> _____________________________________
;%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%
;		Hotkey: F9
;
;		Action 	- Main hotkey for PM App Launcher. Launches the main GUI.
;		Scope	 	- Global. This hotkey will always perform this function while the PM Launcher is
;					  running.
;___________________________________________________________________________________________________
	f9::
		n:=0
		loop {
			n++
			Sleep, 15
			IfGreater, n, 20, Goto HoldHK_Action
			getkeystate, keyVar, f9, P
			IfEqual, keyVar, U, break
		}
		IfWinNotExist, %HoldHK_WindowName%
			goto, main
	return


	;____________________________
	; 	    HOTKEY ACTION - PRESS
	;
	main:
	If WinExist("Permanent Monitoring Apps"){
		WinActivate, Permanent Monitoring Apps
		return
	}
	goto, PMgui_mainGui
	

	;___________________________
	;		HOTKEY ACTION - HOLD
	;
	HoldHK_Action:
		HOLD_WINDOWNAME = 
		HOLD_LAUNCH_LABEL = 
	return
		

	





;_________________________________ CREATE CWI SHORTCUT HOTKEY  <CTRL+F9> ___________________________
;%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%
;	Hotkey: Ctrl + F9
;		
;	Action - Opens a user input prompt that allows the user to assign a shortcut label to an
;			 object in CWI. This is a *very* useful feature that greatly increases efficiency
;			 of finding and viewing CWI objects. The labels created are used by <CWI Search Bar>
;			 to instantly open that object in a CWI window when the label is entered as the search
;			 text - the user can also specify which view (modify, view, print, navigate, where used, 
;			 etc.) to open the part in.. all from one label!
;	Scope  - Application specific. This hotkey action will only trigger if an Internet Explorer window
;			 is active; moreover, a CWI webpage must be active in that IE window. If these requirements
;			 aren't met, then this hotkey has no effect.
;___________________________________________________________________________________________________
^F9::    
	WinGetActiveStats,id,w,h,x,y
	wingettext, wintext, %id%
	wingettitle, title, %id%
	url=
	objectName=
	if (instr(wintext, find) > 0){
		loop, parse, wintext,`n
		{	;_____________________________________________________
			;	  Confirm that a CWI window is active		
			;	  then get these variables:;
			;	url, objType, partID, sapNum (part only)
			;	and objectName (Rtas, Tasks, Specs and Procedures)
			;
			IfInString, a_loopfield, http://cwiprod.corp.halliburton.com/cwi
			{	
				;________________
				;	Get Part ID
				url=%a_loopfield%			
				StringReplace, partid, url, jsp?id=, $
				StringSplit,partID, partid, $
				partID := partID2
				
				;_______________
				; 	Get objType 
				StringSplit, titleWord, title, %a_space%
				objType := titleWord1
				
				;______________________
				;	PART - Get sapNum
				if objType = part 
					sapNum := titleWord2
				
				;____________________________________________
				;	Rta,Task,Spec,Procedure - Get objectName
				if objType = Rta
					stringreplace, objectName, titleword2, R00000,,
				if objType = Task
					StringReplace, objectName, titleword3, T00000,,
				if (objType = "Specification" || objType = "Procedure")
					objectName := titleword2
				break 
			}			
		}
	}
	
	if (url){
	;=================================================================
	;     SUCCESSFULLY OBTAINED A CWI URL FROM WINDOW
	;=================================================================
	
		;________________________
		; 	PROMPT FOR REF NUMBER
		;
		badrefnum:
		inputbox,label, Enter Object Label, Enter the REF. NUMBER of this object:,,220,150,,,,,%objectName%
		if errorlevel
			return
		if label=""
			return
		
		cwi := new cwi()
		
		;==========================
		; WRITE INFO TO INI FILES
		;===========================
			
			;________________________________________________________
			; 	RTA >> Write ID to rtaid.ini [rtaids] section
			;
			if (objType = "Rta")		
				cwi.Add_rtaID(Label, trim(partID))

			;_________________________________________________________
			; 	TASK >> Write ID to rtaid.ini [taskids] section
			;
			else if (objType = "Task")
				IniWrite, % trim(partID), %RTA_INI%, taskids, %label%
			
			;_________________________________________________________
			; 	ALL (EXCEPT task/RTA) >> Write ID to objectids.ini
			;
			else
				cwi.Add_id(Label, trim(partID))

			;________________________________________
			; 	PART >> Also write SAP num info
			;
			if ((objType = "Part") && (sapNum != label))  ;Don't write if SAP num used as label
				cwi.Add_sapNum(Label, Trim(sapNum))
			
	}
return







;_________________________ CREATE PERSONAL SHORTCUT HOTKEY <CTRL+ALT+F9> ___________________________
;%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%
;	Hotkey: Ctrl + Alt + F9
;		
;	Action - Opens a user input prompt that allows the user to assign a shortcut label to any
;			 selected object (such as a program, file, URL, etc.). The selected object can then be
;			 run/launched by typing the assigned label into the <CWI Search Bar>.
;	Scope  - Global. This hotkey is active in any application while the PM App Launcher is running.
;	Usage  - To create a personal shortcut to a file, folder, application, etc., simply select the
;			 item's icon and press the hotkey. In order to create a person shortcut to a website/URL
;			 you must go to the site in a web browser, and select the URL text in the URL bar then
;			 press the hotkey.
;___________________________________________________________________________________________________
^!F9::    
	cbBU:=Clipboard
	Clipboard=
	send, ^c
	sleep 75
	if (errorlevel) {
		msgbox, No file/path found. Cannot create quick link.
		return
	}
	;Prompt for name
	;=================
	inputbox, label,PERSONAL LABEL, Enter label that calls this page:,,200,120
		if errorlevel
			return
		if label=""
			return
		
		; Check for personal shortcuts folder
		;======================================
		IfNotExist, %PERSONAL_SC%
			FileCreateDir, %PERSONAL_SC%
		
		;Label already exists
		IfExist, %PERSONAL_SC%\%label%.lnk
		{   MsgBox, 52, Already Exists, %label% already exists as a label. Overwrite?
			IfMsgBox, yes
			{   FileCreateShortcut, %Clipboard%, %PERSONAL_SC%\%label%.lnk
				Clipboard:=cbBU
				return
			}
			IfMsgBox, no    
			{  Clipboard:=cbBU                
				return
			}
		}        
		FileCreateShortcut, %Clipboard%, %PERSONAL_SC%\%label%.lnk
		Clipboard=
		Clipboard:=cbBU
return






;____________________________________ H O T S T R I N G S __________________________________________
;%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%



	;==============================================================
	;	 CONVERTS A XXXX-XXXX Number TO SAP NUM - TRIGGER: !@
	;==============================================================
	:*C1R0B?C0:!@::
		Send, {BLIND}+{Left 9}
		CBB:=Clipboard
		Clipboard=
		Send, ^c
		Sleep 25
		
		IniRead, sapNUM, %epub%\PM App Logs\StrMgmtLks\partsapnums.ini, sapnums, %Clipboard%, Error
		If (sapnum = "Error"){
			Send, {BLIND}^v{right}
			Return
		}
		Clipboard:=sapnum
		Sleep 25
		Send, ^v
		Clipboard:=cbb
	Return
	





;____________________________________  .E.N.D.   .O.F.   .F.I.L.E. _________________________________
;%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%

